package lab03.test14;
import  java.sql.*;
public class Test14 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;
try {
    connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC&characterEncoding=gbk","root","w19971201t");
    statement=connection.createStatement();
    statement.execute("CREATE TABLE t_userinfo(usercode varchar(4) NOT NULL ,username varchar(10),password varchar(6), email  varchar(40),  primary key(usercode))");
statement.executeUpdate("INSERT  INTO t_userinfo VALUES ('7101','宋晓梅','123456','xiaomei@yahoo.com.cn')");
    statement.executeUpdate("INSERT  INTO t_userinfo VALUES ('7102','关松节','654321','songjie@263.net')");
    statement.executeUpdate("INSERT  INTO t_userinfo VALUES ('7103','李晓梅','123654','xiaomei@yahoo.com.cn')");
resultSet=statement.executeQuery("SELECT  * FROM t_userinfo");
    while (resultSet.next()){
        System.out.print(resultSet.getString(1)+" ");
        //getString为列号
        System.out.print(resultSet.getString(2)+" ");
        System.out.print(resultSet.getString(3)+" ");
        System.out.print(resultSet.getString(4)+" ");
        System.out.println();

    }
}


catch (SQLException e) {
    e.printStackTrace();
}
finally {
    try {
        connection.close();
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }

}

    }
}
